<%@ page import="com.scalar.chiptrack.utils.ConfigManager,
                 com.scalar.chiptrack.commons.Constants,
                 com.scalar.chiptrack.operations.process.forms.BomPartEntryForm"%>
 <%--
  Created by IntelliJ IDEA.
  User: Murali Krishna Yengala
  Date: May 12, 2005
  Time: 10:25:54 AM
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>

<chiptrack:checkLogon sourcePage="/bomPartEntry.do?action=selectBom" />
<%String chipTracContext = "/" + ConfigManager.getChipTracContext(); /*try {*/ %>
<html>
    <HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
        <META http-equiv=Content-Type content="text/html; charset=windows-1252">
        <LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type="text/css" rel="stylesheet">
    </HEAD>
    <BODY bgColor="#ffffff" leftMargin="0" topMargin="0" marginheight="0" marginwidth="0" >
    <script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></script>
    <script src="<%=chipTracContext%>/jsp/includes/scripts/bomPartEntry.js"></script>
    <script src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></script>
    <SCRIPT language="JavaScript">

    function submitPage( action )
    {
        var pa	= document.getElementById("errors");
        var form = document.bomPartEntryForm;
		pa.innerHTML = '';
        if( action == 'LOADLOCATIONS')
        {
            form.action.value = "LoadLocations";
            form.submit();
        }
        if(action == 'OPEN')
		{
            var errors = '';
            var pa = document.getElementById("errors");
            if ((form.productId.value == '0')|| (form.productId.value == '-1'))
			{
                pa.innerHTML = "<li> Please select a valid Part Number " ;
                return;
            }
			form.action.value = "OpenBom";
            form.submit();
        }
		else if( action == 'SAVE' )
		{
            if ((form.productId.value == '0')|| (form.productId.value == '-1'))
            {
            pa.innerHTML = "<li> Please select a valid Part Number " ;
            return;
            }

            if( form.partNbr.value.trim().length < 1)
            {
            pa.innerHTML = "<li> Please enter Bom Part Number ";
            form.partNbr.value="";
            form.partNbr.focus();
            return;
            }
            if( form.partNbr.value.indexOf("'") >= 0 )
            {
                pa.innerHTML = "<li> Please enter Bom Part Number without single quotes ";
                form.partNbr.select();
                form.partNbr.focus();
                return;
            }
            if( form.partNbr.value.indexOf('"') >= 0 )
            {
                pa.innerHTML = "<li> Please enter Bom Part Number without double quotes ";
                form.partNbr.select();
                form.partNbr.focus();
                return;
            }
            if ( !checkDuplicatesForAlternateVendorParts() )
            {
                return;
            }
            if ( !vendorValidations(form) )
            {
                pa.innerHTML = "<li> Please select atleast one vendor";
                return;
            }
            form.action.value = "SaveBomPart";
            if ( checkValuesForBoardMaking () )
            {
                form.submit();
            }
        }

    }

    function checkDuplicatesForAlternateVendorParts()
    {
        var pa = document.getElementById("errors");
		var errors = '';
		pa.innerHTML = errors;
        var form = document.forms["bomPartEntryForm"];
        var alternateVendorPartsCtrl = form.elements["alternateVendorParts"];
        if ( alternateVendorPartsCtrl.length != 'undefined' )
        {
            for( var k = 0; k < alternateVendorPartsCtrl.length; k++ )
            {
                var name  = alternateVendorPartsCtrl[k].value.trim();
                if( name != '' )
                {
                    for( var i = 0; i < k; i++ )
                    {
                        var lastName = alternateVendorPartsCtrl[i].value;
                        if( name.trim().toUpperCase() == lastName.trim().toUpperCase() )
                        {
                            errors = errors+"<li> Alternate Vendor Parts '" + lastName.trim() + "' already exists please enter another name";
                            pa.innerHTML = errors;
                            alternateVendorPartsCtrl[k].focus();
                            return false;
                        }
                    }
                }
            }
        }
        return true;
    }
    function addAlternateVendorPartField( )
    {
        var table = document.getElementById("alternateVendorPartTable");
        var newRow = table.insertRow();
        var td = newRow.insertCell();
        td.innerHTML = '<input type=text name="alternateVendorParts" class=txfield size="20" maxlength="50" />';
    }


    </script>
    <!-- Top Header Start-->
    <%@ include file="/jsp/includes/header.jsp" %>
    <!-- Top Header End-->
    <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
      <TBODY >
      <TR>
        <TD width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>

        <!-- Side Navigation start -->
        <%@ include file="/jsp/operations/product_menu.jsp" %></TD>
        <!-- end of the side navigations -->

        <TD bgcolor="#ffffff">
        <IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
        <TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
        <TD valign="top" width="100%">

        <IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
        <BR>
        <!-- from here your body starts -->
        <html:form action="/bomPartEntry" name="bomPartEntryForm" type="com.scalar.chiptrack.operations.process.forms.BomPartEntryForm">
        <input type="hidden" name="action" value="">
            <TABLE width='85%' align=right cellpadding='3' cellspacing='2' border='0' bordercolor='black'>
                <TR><Td colspan='4' class="NArialW" align=center>BOM Part Entry</td></tr>
                <TR><TD colspan='4'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='10'></TD></TR>
                <% if ( !user.isActionAllowed ( Functionality.BOM_PART_ENTRY, User.USER_ACTION_MODIFY  )  ) { %>
                <tr><td colspan='4'>
                <font class='NArialS' color='blue'><b><%=Constants.NO_MODIFY_RIGHTS %></b>
                </font></td></tr>
                <% } %>
                <tr><td colspan='4' align="left" class='NArialL'>&nbsp;<FONT id="errors" color='FF0000'></font></td></tr>
                <TR><TD colspan='4'><chiptrack:errors styleClass="NArialL"/></TD></TR>
                <TR><TD colspan='4'><chiptrack:info styleClass="NArialL"/></TD></TR>
                <%--<TR><TD colspan='4'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='10'></TD></TR>--%>
                <TR><TD class='NArialL' width="30%"> BOM Part Number :<br>
                <%--(<bean:message key = "label.mfgPartNumber" />)--%>
                </TD>
                    <TD class="NArialL" colspan='3'>
                        <html:select property="productId" styleClass="txfield"  onchange="javascript:submitPage('OPEN');" >
                        <html:option value="-1">Select BOM</html:option>
                        <html:option value="-2">Add New BOM</html:option>
                        <html:option value="0">-----------</html:option>
                        <html:options collection="bomParts" property="value" labelProperty="label"/>
                        </html:select>
                    </TD>
                </TR>
                <TR><TD colspan='4'>
                    <IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='4'>
                </TD></TR>

                <logic:equal name="showDetails" value="TRUE">
                <TR>
                    <TD class='NArialL' colspan='1'>Bom Part Number : <font color="RED" size="1"><B> *</B></font></TD>
                    <TD class="NArialL" colspan='3'>
                    <input type="hidden" name="originalPartNumber" value="<bean:write name='bomPartEntryForm' property='partNbr'/>">
                        <html:text name="bomPartEntryForm" property="partNbr" styleClass="txfield" maxlength="50" size="20" />
                    </TD>
                 </TR>
                <TR>
                    <TD class='NArialL' colspan='1'>Bom Process Type : </TD>
                    <TD class="NArialL" colspan='3'>
                    <logic:greaterThan value="0" property="productId" name="bomPartEntryForm">
                        <html:select property='processType' styleClass='txfield' disabled='true'>
                            <html:options collection='processTypes' labelProperty="label" property='value'/>
                        </html:select>
                    </logic:greaterThan>
                    <logic:lessEqual value="0" property="productId"  name="bomPartEntryForm">
                        <html:select property='processType' styleClass='txfield' onchange="submitPage('LOADLOCATIONS')">
                            <html:options collection='processTypes' labelProperty="label" property='value'/>
                        </html:select>
                    </logic:lessEqual>
                    </TD>
                 </TR>
                <%--<input type="hidden" name="originalPartNumber" value="<bean:write name='bomPartEntryForm' property='partNbr'/>">--%>
                <TR>
                    <TD class='NArialL' colspan='1'>Vendor Part Number : </TD>
                    <TD class="NArialL" colspan='3'>
                    <table id="alternateVendorPartTable" cellSpacing=0 cellPadding=0>
                    
                    <logic:present name="bomPartEntryForm" property="alternateVendorParts">
                        <bean:size id="size" name="bomPartEntryForm" property="alternateVendorParts"/>
                        
                        <logic:greaterThan value="0" name="size">
                            <logic:iterate name="bomPartEntryForm" property="alternateVendorParts" id="alternateVendorPart" indexId="idx" type="java.lang.String">
                                <tr>
                                    <td nowrap>
                                        <%--<html:text name="bomPartEntryForm" property="alternateVendorParts" styleClass="txfield" maxlength="50" size="20" />--%>
                                        <input type="text" name="alternateVendorParts" size="20" maxlength="50" class="txfield" value="<%= new String( alternateVendorPart.getBytes("ISO-8859-1"), "UTF-8")%>">
                                        <logic:equal value="0" name="idx">
                                            <a href="javascript:addAlternateVendorPartField();" onMouseOver="window.status='Click to Add New Alternate Vendor Part';return true" onMouseOut="window.status='';return true"title='Click here to Add New Alternate Vendor Part'><img border=0 src='<%=chipTracContext%>/jsp/includes/images/add.jpg' height='15' width='20' align="middle"></a>
                                        </logic:equal>
                                    </td>
                                </tr>
                            </logic:iterate>
                        </logic:greaterThan>
                            <logic:lessEqual value="0" name="size">
                                <tr>
                                    <td nowrap>
                                        <%--<html:text name="bomPartEntryForm" property="alternateVendorParts" styleClass="txfield" maxlength="50" size="20" />--%>
                                    <input type="text" name="alternateVendorParts" size="20" maxlength="50" class="txfield" value="">
                                    <a href="javascript:addAlternateVendorPartField();" onMouseOver="window.status='Click to Add New Alternate Vendor Part';return true" onMouseOut="window.status='';return true"title='Click here to Add New Alternate Vendor Part'><img border=0 src='<%=chipTracContext%>/jsp/includes/images/add.jpg' height='15' width='20' align="middle"></a>
                                    </td>
                                </tr>
                            </logic:lessEqual>
                    </logic:present>
                    <logic:notPresent name="bomPartEntryForm" property="alternateVendorParts">
                        <tr>
                            <td nowrap>
                                <%--<html:text name="bomPartEntryForm" property="alternateVendorParts" styleClass="txfield" maxlength="50" size="20" />--%>
                            <input type="text" name="alternateVendorParts" size="20" maxlength="50" class="txfield" value="">
                             <a href="javascript:addAlternateVendorPartField();" onMouseOver="window.status='Click to Add New Alternate Vendor Part';return true" onMouseOut="window.status='';return true"title='Click here to Add New Alternate Vendor Part'><img border=0 src='<%=chipTracContext%>/jsp/includes/images/add.jpg' height='15' width='20' align="middle"></a>
                            </td>
                        </tr>
                    </logic:notPresent>

                    </table>
                    </TD>
                </TR>
                <TR>
                    <TD class='NArialL'>Description : </TD>
                    <TD colspan='3'>
                        <html:textarea name="bomPartEntryForm" property="description" styleClass="txfield" rows="4" cols="45" onkeydown="javascript:setTextAreaMaxLength(this,300)" onkeyup="javascript:setTextAreaMaxLength(this,300)"/>
                    </TD>
                 </TR>
                <TR>
                    <TD class='NArialL'>Max Quantity : </TD>
                    <TD class="NArialL">
                        <html:text name="bomPartEntryForm" property="maxQuantity" styleClass="txfield" maxlength='6' onkeypress="allowInteger()"/>
                    </TD>
                    <TD class='NArialL'>Min Quantity : </TD>
                    <TD class="NArialL">
                        <html:text name="bomPartEntryForm" property="minQuantity" styleClass="txfield" maxlength='6'  onkeypress="allowInteger()"/>
                    </TD>
                 </TR>
                <TR>
                    <TD class='NArialL'>Reorder Level : </TD>
                    <TD class="NArialL" colspan='3'>
                        <html:text name="bomPartEntryForm" property="reorderLevel" styleClass="txfield" maxlength='6' onkeypress="allowInteger()"/>
                    </TD>
                 </TR>
                 <br>
                 <TR><TD colspan='4'>
                    <table width="80%" border='0'>
                        <tr><td class="NArialL" height="18" colspan=3>Vendor Location Information :<font color="RED" size="1"><B>*</B></font></td></tr>
                        <tr>
                            <td width="10%" align="center" bgcolor="#993333" height="1" class="NArialL"><font color="#FFFFFF">Select</font></td>
                            <td width="10%" align="center" bgcolor="#993333" height="1" class="NArialL"><font color="#FFFFFF">Priority</font></td>
                            <td width="80%" align="center" bgcolor="#993333" height="1" class="NArialL"><font color="#FFFFFF">Location</font></td>
                        </tr>
                        <%int idd = 0;%>
                        <logic:iterate name="bomPartEntryForm" property="vendorLocations" id="vendors" type="com.scalar.chiptrack.operations.process.VendorLocation" indexId="chkCount">
                            <tr>
                                <td width="20%" align="center" bgcolor="#DEE1E2"
                                height="1"><font class="NArialL">
                                <font color="#FFFFFF">
                                <%
                                String str = "checkLocationForBom("+ chkCount +")";
                                %>
                                <html:checkbox name="vendors" property="select" styleClass="txfield" onclick="<%=str%>" />
                                </font></font></td>
                                <td width="20%" align="center" bgcolor="#DEE1E2" height="1">
                                <font class="NArialL" color="#FFFFFF">
                                <logic:equal name="vendors" property="select" value="on">
                                <html:text name="vendors" property="priority" size="6" maxlength="4" styleClass="txfield" disabled="true" />
                                </logic:equal>
                                <logic:notEqual name="vendors" property="select" value="on">
                                <html:text name="vendors" property="priority" size="6" maxlength="4" styleClass="txfield" value="" disabled="true" />
                                </logic:notEqual>
                                </font></td>
                                <td width="60%" align="center" bgcolor="#DEE1E2" height="1"><font class="NArialL"><font color="#FFFFFF">
                                    <html:text name="vendors" property="locationName" disabled="true" size='40' styleClass="txfield" />
                                    <html:hidden name="vendors" property="locationID" />
                                </font></font></td>
                            </tr>
                        <% idd++; %><!--Very important please dont delete.-->
                        </logic:iterate>
                    </table></TD>
                 </TR>
                 </TABLE>
                 </TD></TR>
                <TR><TD colspan='4'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='10'></TD></TR>
                 <TR><TD colspan='4' align=center>
                        <chiptrack:restrictedLink functionality='<%=Functionality.BOM_PART_ENTRY%>' action='<%=User.USER_ACTION_MODIFY%>' href="javascript:submitPage('SAVE');" onmouseover="window.status='Click to save Bom details';return true" onmouseout="window.status='';return true">
                        <img border="0" src="<%=chipTracContext%>/jsp/includes/images/save.gif" width="53" height="17" title="Click here to save Bom details"></chiptrack:restrictedLink>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <A HREF="javascript:document.bomPartEntryForm.reset();"><IMG src="<%=chipTracContext%>/jsp/includes/images/reset.gif" border=0 onmouseover="window.status='Click to Reset';return true" onmouseout="window.status='';return true" title="Click here to Reset"></A>
                     </TD>
                  </TR>
                 <input type="hidden" name="count" value="<%=idd%>">
                </logic:equal>
                </TABLE>

        </html:form>
        <!-- till here -->
        
        </TABLE>
        </TD>

        </TR>
        </TABLE>
        <!-- Footer starts here -->
        <%@ include file="/jsp/includes/footer.jsp" %>
        <!-- footer end here -->
    </body>
</html>
<%--
    }
    catch (Exception e )
    {
        e.printStackTrace();
    }
    --%>
